package base.mail.lib;

import java.util.Properties;
import javax.mail.Authenticator;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import base.config.lib.MSNJOBConfig;

/**
 * 定义常用发送邮件方法
 * @author admin
 *
 */
public class MailUtil {
	//基本信息
	private static Properties mail_prop = new Properties();
	//回话对象
	private static Session session;
    /**
     * 设置初始化参数
     * @throws Exception 
     */
	public static void init_params() throws Exception{
//		System.out.println(MSNJOBConfig.getInstance().getMail_smtp_auth());
//		System.out.println(MSNJOBConfig.getInstance().getMail_transport_protocol());
//		System.out.println(MSNJOBConfig.getInstance().getMail_smtp_host());
//		System.out.println(MSNJOBConfig.getInstance().getMail_username());
//		System.out.println(MSNJOBConfig.getInstance().getMail_password());
		
		mail_prop.setProperty("mail.smtp.auth", MSNJOBConfig.getInstance().getMail_smtp_auth());
		mail_prop.setProperty("mail.transport.protocol", MSNJOBConfig.getInstance().getMail_transport_protocol());
		mail_prop.setProperty("mail.smtp.host", MSNJOBConfig.getInstance().getMail_smtp_host());
		final String username=MSNJOBConfig.getInstance().getMail_username();
		final String password=MSNJOBConfig.getInstance().getMail_password();
		session = Session.getInstance(mail_prop, new Authenticator() {
			protected PasswordAuthentication getPasswordAuthentication() {
				return new PasswordAuthentication(username,password);
			}
		});
		//调试信息
		session.setDebug(true);
	}

}
